package com.xintool.window.Buttons;

import javax.swing.*;
import javax.swing.plaf.basic.BasicButtonUI;
import java.awt.*;

public class ButtonFactory extends JButton  {
    public static JButton getButton(String text){
        JButton button = new JButton(text);//按钮显示文本为text
        //设置字体和大小
        button.setFont(new Font("微软雅黑", Font.PLAIN, 12));

        //设置按钮大小
        button.setPreferredSize(new Dimension(90,27));

        return button;
    }

    public JButton showButton(){

        // 利用按钮工厂创建按钮实例
        JButton button = ButtonFactory.getButton("text");//按钮显示文本为text

        //添加点击事件监听
        button.addActionListener(e -> {
            JOptionPane.showMessageDialog(this.showButton(), "！");
        });
        return button;
    }

    @Override
    public void setMargin(Insets m) {
        super.setMargin(m);
    }
}
